package controller;

import java.util.Iterator;
import java.util.List;

import competition.Competition;
import competitionImpl.CompetitionFactory;
import competitionImpl.CompetitionImpl;
import competitionImpl.EquipeImpl;
import competitionImpl.MatchImpl;

public class actionAfficherCompet  {

	/**
	 * 
	 */

	private String dataCompet;
	private int typeCompet;
	private CompetitionFactory factory;
	private Competition c;



	/**
	 * @return the c
	 */
	public List<MatchImpl> getMatchs() {
		return c.getMatchs();
	}



	/**
	 */
	public actionAfficherCompet(){

		this.factory = new CompetitionFactory();	
	}



	public void createCompet() {




		//type 0 : Tournoi
		//type 1 : coupe simple
		//type 2 : coupe avec poules

		switch (this.typeCompet) {
		case 0:
			this.c = this.factory.genererTournoi(this.dataCompet);
			break;
		case 1:
			this.c = this.factory.genererCoupeSimple(this.dataCompet);
			break;
		case 2:
			this.c = this.factory.genererCoupeAvecPoules(this.dataCompet);
			break;

		default:
			throw new RuntimeException();
		}



	}



	public Object[][] getTabDataCompet() {

		Object[][] tabData = null;



		try {

			int size = this.c.getEquipes().size();

			tabData = new Object[size][2];

			Iterator<EquipeImpl> iterator = this.c.getEquipes().iterator();
			int i = 0;

			while( iterator.hasNext() && i < size) {
				EquipeImpl equipe = (EquipeImpl) iterator.next();
				if(equipe != null){
					tabData[i][0] = equipe.getNom();
					tabData[i][1] = equipe.getNbVict();
				}
				i++;
			}

		} catch (NullPointerException e) {
			e.printStackTrace();
		}


		return tabData;
	}


	/**
	 * @return the typeCompet
	 */
	public String getTypeCompet() {
		return ((CompetitionImpl) this.c).getLibelle();
	}


	/**
	 * @param typeCompet the typeCompet to set
	 */
	public void setTypeCompet(int typeCompet) {
		this.typeCompet = typeCompet;
	}


	/**
	 * @param dataCompet the dataCompet to set
	 */
	public void setDataCompet(String dataCompet) {
		this.dataCompet = dataCompet;
	}



	public String getVainqueur() {
		return this.c.getVainqueur().getNom();
		
	}








}
